package von.seiji.cn.test;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.extra.pinyin.PinyinUtil;
import cn.hutool.extra.template.Template;
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.TemplateUtil;
import org.dom4j.Document;
import org.dom4j.Element;
import org.junit.Test;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import von.seiji.cn.*;
import java.io.File;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @Author: Amasawa Seiji
 * @Since: 2021/1/28 11:14
 * @Description: 暂无描述
 */
public class T1 {

    @Test
    public void test11() {
        String str = "adfsdfdsf";
       /* String a = StrUtil.capitalize(str, new char[]{'f'});
        String b = StrUtil.capitalizeFully(str);
        System.out.println(a);
        System.out.println(b);
        String aDkfDfd = StrUtil.uncapitalize("ADkfDfd", new char[]{'_'});
        System.out.println(aDkfDfd);*/
    }

    @Test
    public void test25() {
        System.out.println(Character.toTitleCase('r'));
        byte[] decode = Base64Util.decode("");
        System.out.println(new String(decode));

    }

    @Test
    public void test37() {
        // new JSONObject().getBoolean()
       /* String safasfs = StrUtil.capitalize("safasfs");
        System.out.println(safasfs);//Safasfs
        String dsafd = StrUtil.capitalize("dsafd", new char[]{'s'});
        System.out.println(dsafd);//DsAfd
        String safasfs1 = StrUtil.capitalizeFully("safasfs");
        System.out.println("safasfs1 = " + safasfs1);*/
    }

    @Test
    public void test49() {
        Mat imread = Imgcodecs.imread("C:\\Users\\Administrator\\Desktop\\11.jpg");
        byte[] jpgs = MatUtil.mat2Byte(imread, "jpg");
    }

    @Test
    public void test58() {
        Document doc = XmlParseUtil.getDoc(new File("F:\\GoogleDownload\\export3.xls"));
        Element rootElement = doc.getRootElement();
        List elements = rootElement.elements();
        elements.forEach(item -> {
            System.out.println(item);
        });
    }

    Timer timer;

    @Test
    public void test70() {
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("Time's up!");
//                timer.cancel();
            }
        }, 0, 100);

    }

    public static void main(String[] args) {
        Timer timer;
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("Time's up!");
//                timer.cancel();
            }
        }, 0, 100);
    }

    String text = "我想写下什么，我在追忆什么，好像告诉你，每刻在想你";
    File pri = new File("C:\\Users\\Administrator\\Desktop\\pri.txt");
    File sec = new File("C:\\Users\\Administrator\\Desktop\\sec.txt");
    @Test
    public void test99() {
        String text = "我想写下什么，我在追忆什么，好像告诉你";
        File file = new File("C:\\Users\\Administrator\\Desktop\\cxt.txt");
        byte[] bytes = SerializeUtil.toByteArray(text);
        String s = HexUtil.encodeHexStr(bytes);

        String str1 = StrUtil.str(bytes, CharsetUtil.UTF_8);
        System.out.println("str1 = " + str1);
//        FileUtil.writeBytes(bytes, file);
        FileUtil.writeString(s, file, CharsetUtil.UTF_8);
        System.err.println("完成写入。");
        //aced0005740048e68891e683b3e58699e4b88be4bb80e4b988efbc8ce68891e59ca8e8bfbde5bf86e4bb80e4b988efbc8ce6ada4e588bbe79a84e68891e58f88e794b1e8b081e694afe9858defbc9f
        String str = "aced0005740048e68891e683b3e58699e4b88be4bb80e4b988efbc8ce68891e59ca8e8bfbde5bf86e4bb80e4b988efbc8ce6ada4e588bbe79a84e68891e58f88e794b1e8b081e694afe9858defbc9f";

    }

    @Test
    public void test124() {
        RSA rsa = SecureUtil.rsa();
        String privateKeyBase64 = rsa.getPrivateKeyBase64();
        FileUtil.writeString(privateKeyBase64, pri, Charset.defaultCharset());
        byte[] encrypt = rsa.encrypt(text, KeyType.PublicKey);
        FileUtil.writeBytes(encrypt, sec);
        System.err.println("加密完成。");
    }

    @Test
    public void test142 () throws Exception {
        String s = FileUtil.readString(pri, CharsetUtil.UTF_8);
        byte[] bytes = FileUtil.readBytes(sec);
        RSA rsa = SecureUtil.rsa(s, null);
        byte[] decrypt = rsa.decrypt(bytes, KeyType.PrivateKey);
        System.out.println(StrUtil.str(decrypt, CharsetUtil.UTF_8));

    }

    /**
     * freemarker
     */
    @Test
    public void testewr() {
        TemplateEngine engine = TemplateUtil
                .createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
        Template template = engine.getTemplate("email/email.ftl");
        String code = RandomUtil.randomNumbers(6);
        String content = template.render(Dict.create().set("code", code));
        System.out.println(content);
        TemplateEngine engine1 = TemplateUtil.createEngine();
        Template template1 = engine1.getTemplate("你好，${code}，欢迎来到地球！！！");
        String code1 = template1.render(Dict.create().set("code", "11111111111"));
        System.out.println("code1 = " + code1);
    }

    @Test
    public void test143() throws Exception {
        Class<?> aClass = Integer.class.getDeclaredClasses()[0];
        Field cache = aClass.getDeclaredField("cache");
        cache.setAccessible(true);
        Integer[] integers = (Integer[]) cache.get(aClass);
        integers[130] = integers[129];
        integers[131] = integers[129];
        Integer a = 1;
        if(a == (Integer)1 && a == (Integer) 2 && a == (Integer) 3){
            System.out.println("Success!!!");
        }
    }

    @Test
    public void testfdsf() {
        String 你好 = PinyinUtil.getPinyin("你好");
        System.out.println("你好 = " + 你好);
    }



}
